<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Register_m extends Model {

    function Register_m() {
        parent::Model();
    }

    function determine_zone($country, $province) {
        if ($country == 'Indonesia') {
            if ($province == 'DKI Jakarta' || $province == 'Jawa Barat' || $province == 'Jawa Tengah' ||
                    $province == 'DI Yogyakarta' || $province == 'Jawa Timur' || $province == 'Banten') {
                return 1;
            } else {
                return 2;
            }
        } else {
            return 3;
        }
    }

    function register_member() {
        $zone = $this->determine_zone($this->input->post('countries'), $this->input->post('indo_provinces'));

        $data_user = array(
            'username' => $this->input->post('username'),
            'password' => sha1($this->input->post('password')),
            'email' => $this->input->post('email'),
            'university' => $this->input->post('university'),
            'zone' => $zone,
            'country' => $this->input->post('countries'),
            'province' => $this->input->post('indo_provinces'),
            'team_name' => $this->input->post('team_name'),
//            'leader_name' => $this->input->post('leader_name'),
//            'leader_gender' => $this->input->post('leader_gender'),
//            'leader_dob' => $this->input->post('leader_dob'),
//            'leader_phone' => $this->input->post('leader_phone')
        );

        $data_member = array(
            'username' => $this->input->post('username'),
            'member_name_1' => $this->input->post('member_name_1'),
            'member_name_2' => $this->input->post('member_name_2'),
            'member_name_3' => $this->input->post('member_name_3'),
            'member_name_4' => $this->input->post('member_name_4')
        );
        //validasi dulu disini
        //yg divalidasi cuma file yg diupload aja
        //kalo field lain divalidasi pake javascript aja



        $this->db->insert('users', $data_user);
        $this->db->insert('team_members', $data_member);
        //upload file
    }

    function validate($username) {
        //gak usah cek persyaratan
        //masukin hashcode ke db
        //return hashcode
        //return text buat diemail di controller
        $hash = md5(random_string());
        $update = array('hash_code' => $hash);
        $this->db->where('username', $username);
        $this->db->update('users', $update);
//        
//        if ($res->num_rows() == 1) {
//
//            foreach ($res->result_array() as $row) {
//                $iscv = $row['is_cv'];
//                $isid = $row['is_id'];
//                $isletter = $row['is_letter'];
//            }
//
//           
//        }
//        else {
//            
//        }
    }

    function send_confirmation_email($destination, $hash_code) {
        //tampilin kode hash
        //tampilin link ke controller -> /registration/validate/<username>/<hash code>
    }

    function send_timechoice_email($destination) {
        
    }

    function activate_account() {
        
    }

}

?>
